<?php
//$db = new PDO('mysqli:host=localhost;dbname=db3','root','12qwas');
//$ps=$db->prepare('select * from students limit ?');
//$ps->bindValue(1,2,PDO::PARAM_INT);
//$ps->execute();
//foreach ($ps as $r){
//    echo "{$r['xh']}\t{$r['age']}\n";
//}
//$db = new PDO('mysql:host=localhost; dbname=db3', 'root', '12qwas');
//$ps=$db->prepare('select * from students limit :offset, :length');
//$ps->bindParam(':offset',$offset,PDO::PARAM_INT);//此变量作为引用被绑定
//$ps->bindParam(':length',$length,PDO::PARAM_INT);
//$offset=$length=1;
//$ps->execute();//只在 PDOStatement::execute()被调用的时候才取绑定变量的值。
//foreach ($ps as $r){
//    echo "{$r['xh']}\t{$r['name']}\t{$r['age']}\n";
//}
//$db = new PDO('mysql:host=localhost; dbname=db3', 'root', '12qwas');
//$ps=$db->prepare('select * from students limit 1,2');
//$ps->bindColumn(1,$xh);
//$ps->bindColumn(2,$name);
//$ps->bindColumn('age', $age, PDO::PARAM_INT);
//$ps->execute();
//foreach ($ps as $r){
//    echo "{$xh}\t{$name}\t{$age}\n";
//}

//$db = new PDO('mysql:host=localhost; dbname=db3', 'root', '12qwas');
//$ps=$db->query('select name from students limit 1 ');
//var_dump($ps->fetch());
//var_dump($ps->fetch());


//$db = new PDO('mysql:host=localhost; dbname=db3', 'root', '12qwas');
//$ps=$db->query('select count(*) from students');
//echo "记录个数为：{$ps->fetchColumn()}\n";


$db = new PDO('mysql:host=localhost; dbname=db3', 'root', '12qwas');
$ps=$db->query('select * from students');
$rs=$ps->fetchAll();
//print_r($rs);
echo "{$rs[0]['xh']}\t{$rs[1]['name']}\t{$rs[2]['age']}";